// pages/income/income.js
import wxCharts from '../../utils/wxcharts.js'
// var wxCharts = require('../../utils/wxcharts.js');


Page({

  /**
   * 页面的初始数据
   */
  data: {
    income1:45.0,
    income2:25.0,
    diff1:5.0,
    diff2:-5.0,
    good:[10,80,90,20,30,40,50,12,32,12.1,10,1],
    ad:[20,30,9,2,100,20.2,30.1,12,32,22.1,1,4]

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    echartsdt(this)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
})

function echartsdt(vm) {
  var windowWidth = '',
    windowHeight = ''; //定义宽高
  try {
    var res = wx.getSystemInfoSync(); //试图获取屏幕宽高数据
    windowWidth = res.windowWidth / 750 * 650; //以设计图750为主进行比例算换
    windowHeight = res.windowWidth / 750 * 500 //以设计图750为主进行比例算换
  } catch (e) {
    console.error('getSystemInfoSync failed!'); //如果获取失败
  }
  new wxCharts({
    canvasId: 'income',
    type: 'line',
    categories: ["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],
    animation: true,
    legend: true,
    series: [{
      name: "商品利润",
      data: vm.data.good,
      color: '#9ad672' ,
      format: function (val, name) {
        return val.toFixed(2) + '元';
      }
    },
    {
      name: "广告收入",
      data: vm.data.ad,
      color: '#4E5969',
      format: function (val, name) {
        return val.toFixed(2) + '元';
      }
    }],
    yAxis: {
      min: 0,
      gridColor: '#e0e6f1',
      type: 'value'
    },
    xAxis: {},
    extra: {
      legendTextColor: '#333',
    },
    width: windowWidth * 1.1, //图表展示内容宽度
    height: windowHeight, //图表展示内容高度
  });
}